package com.controller;

import com.entity.UserFile;
import com.entity.UserMetadata;
import com.service.UserFileOperator;
import com.util.CookieUtil;
import com.util.LocalInformation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

/**
 * Created by wlc on 2018/4/14.
 */

/**
 * 映射主页部分
 */
@Controller
@RequestMapping(value = "/System_home_part",produces = "text/html;charset=UTF-8")
public class SystemHomeController {
    //映射System_home.jsp
    @RequestMapping(value = "/Homepage",produces = "text/html;charset=UTF-8")
    public ModelAndView Homepage(HttpServletRequest request){
        ModelAndView modelAndView = new ModelAndView();

        String user_cookie_value = CookieUtil.getUserCookie(request).getValue();
        if (user_cookie_value != null && UserMetadata.OnlineUserId.containsKey(user_cookie_value)){
            UserMetadata.OnlineUserOperatorTime.replace(user_cookie_value, LocalInformation.getTimeID());
            //操作
            ArrayList<UserFile> bulletinFilesInfo = UserFileOperator.getAllFilesInfo("通知");
            ArrayList<UserFile> computeFilesInfo = UserFileOperator.getAllFilesInfo("计算");
            ArrayList<UserFile> experimentFilesInfo = UserFileOperator.getAllFilesInfo("实验");
            ArrayList<UserFile> followFilesInfo = UserFileOperator.getAllFilesInfo("随访");

            modelAndView.addObject("bulletinFilesInfo",bulletinFilesInfo);
            modelAndView.addObject("computeFilesInfo",computeFilesInfo);
            modelAndView.addObject("experimentFilesInfo",experimentFilesInfo);
            modelAndView.addObject("followFilesInfo",followFilesInfo);
            modelAndView.setViewName("SystemHome");
        }else {
            modelAndView.setViewName("login");
        }
        return modelAndView;
    }
}
